<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    private $cate;

    // 初始化
    protected function _initialize()
    {
        $cate = model('Category')->getCategorytree();
        $this->cate = $cate;
        $this->assign('cate', $cate);
    }

    //首页
    public function index()
    {
        return $this->fetch();
    }

    //分类列表
    public function cate()
    {
        $pid = input('pd', '', 'intval');
        $cate_id = input('cate', '', 'intval');
        if (!$pid) {
            $pid = Db::name('Category')->where('id', $cate_id)->value('pid');
        }
        $this->assign('cate_id',$cate_id);
        $this->assign('pid',$pid);
        return $this->fetch('list');
    }

    //三级分类列表
    public function cate_three()
    {
        $cate_id=input('cate','','intval');
        return $this->fetch('list_three');
    }

    //咨询详情页
    public function detail()
    {
        $id=input('id','','intval');
        $row=Db::name('Article')->where(array('id'=>$id))->find();
        if(empty($row)){
            return $this->fetch("Public:404");
        }
        $cate_row=Db::name('Category')->where(array('id'=>$row['c_id']))->find();
        $row['cate_name']=$cate_row['name'];
        $this->assign('row',$row);
        return $this->fetch();
    }

}
